package self.hoy.demo.rabbitmq.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import self.hoy.demo.rabbitmq.Constant;
import self.hoy.demo.rabbitmq.util.ConnectionUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author hyh
 * @date 2020/6/7
 */
public class Send implements Constant {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明队列
        channel.queueDeclare(WORK_QUEUE_NAME, false, false, false, null);
        for (int i = 0; i < 50; i++) {
            String msg = "this is No." + (i + 1) + " message";
            System.out.println(msg);
            channel.basicPublish("", WORK_QUEUE_NAME, null, msg.getBytes());
            Thread.sleep(i + 50);
        }
        channel.close();
        connection.close();
    }
}
